home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2005 March / Macworld CD March 2005 - Marathon Trilogy.iso / Shareware World / User Interface / RocketLauncher.sit / RocketLauncher / RocketLauncher.CVS / RocketLauncher.m,v < prev    next >
Encoding:
Text File  |  2005-01-09  |  4.2 KB  |  192 lines

  1. head    1.3;
  2. access;
  3. symbols
  4.     start:1.1.1.1 oleg:1.1.1;
  5. locks; strict;
  6. comment    @// @;
  7.  
  8.  
  9. 1.3
  10. date    2005.01.09.20.13.54;    author oleg;    state Exp;
  11. branches;
  12. next    1.2;
  13.  
  14. 1.2
  15. date    2005.01.09.19.22.43;    author oleg;    state Exp;
  16. branches;
  17. next    1.1;
  18.  
  19. 1.1
  20. date    2005.01.09.18.45.06;    author oleg;    state Exp;
  21. branches
  22.     1.1.1.1;
  23. next    ;
  24.  
  25. 1.1.1.1
  26. date    2005.01.09.18.45.06;    author oleg;    state Exp;
  27. branches;
  28. next    ;
  29.  
  30.  
  31. desc
  32. @@
  33.  
  34.  
  35. 1.3
  36. log
  37. @No log message.
  38. @
  39. text
  40. @#import "RocketLauncher.h"
  41. #import "AppInfo.h"
  42.  
  43. @@implementation RocketLauncher
  44.  
  45. -(void)setAllApps {
  46.     NSArray *aa = [AppInfo allApps:allApps];
  47.     [allApps release];
  48.     allApps = [aa retain];
  49. }    
  50.  
  51. -(void)setApps {
  52.     [resultTable deselectAll:nil];
  53.     NSString *sv = [searchField stringValue];
  54.     NSCharacterSet *ws = [NSCharacterSet whitespaceAndNewlineCharacterSet];
  55.     NSCharacterSet *alNum = [NSCharacterSet alphanumericCharacterSet];
  56.     NSCharacterSet *upper = [NSCharacterSet uppercaseLetterCharacterSet];
  57.     sv = [sv stringByTrimmingCharactersInSet:ws];
  58.     size_t len = [sv length];
  59.     [apps removeAllObjects];
  60.     if (len == 0) {
  61.         [apps addObjectsFromArray:allApps];
  62.         [resultTable reloadData];
  63.         return;
  64.     }
  65.     int i;
  66.     NSString *matchApp = [prefs appForString:sv];
  67.     int matchIdx = 0;
  68.     for (i = 0; i < [allApps count]; i++) {
  69.         AppInfo *ai = [allApps objectAtIndex:i];
  70.         NSString *name = [ai name];
  71.         size_t nlen = [name length];
  72.         NSRange scope = NSMakeRange(0, nlen);
  73.         BOOL matches = NO;
  74.         while (scope.length > 0) {
  75.             NSRange r = [name rangeOfString:sv options:NSCaseInsensitiveSearch range: scope];
  76.             if (r.location == NSNotFound) break;
  77.             if (r.location == 0) { matches = YES; break; }
  78.             unichar pc = [name characterAtIndex:r.location-1], c = [name characterAtIndex:r.location];
  79.             if (![alNum characterIsMember:pc]) { matches = YES; break; }
  80.             if ([upper characterIsMember:c] && ![upper characterIsMember:pc]) { matches = TRUE; break; }
  81.             // Put word matching rules for your favourite language here
  82.             scope.location = r.location+1;
  83.             scope.length = nlen-scope.location;
  84.         }
  85.         if (matches) {
  86.             if (matchApp != nil && [matchApp isEqual:[ai name]])
  87.                 matchIdx = [apps count];
  88.             [apps addObject:ai];
  89.         }
  90.     }
  91.     [resultTable reloadData];
  92.     
  93.     if ([resultTable numberOfRows] > 0) {
  94.         [resultTable selectRow:matchIdx byExtendingSelection:NO];
  95.         [resultTable scrollRowToVisible:matchIdx];
  96.     }
  97. }
  98.  
  99.  
  100. -(void)awakeFromNib {
  101.     NSRange r = [@@"testtest" rangeOfString:@@"st" options:0 range:NSMakeRange(4, 4)];
  102.     [self setAllApps];
  103.     apps = [[NSMutableArray alloc] init];
  104.     appDS = [[AppTableDS alloc] init];
  105.     [appDS setAppList:apps];
  106.     NSTableColumn *ic = [resultTable tableColumnWithIdentifier:@@"i"];
  107.     [ic setDataCell: [[NSImageCell alloc] init]];
  108.     [resultTable setDataSource: appDS];
  109.     //[[NSApplication sharedApplication] setDelegate:self];
  110.     [self setApps];
  111.     prefs = [SearchPrefs new];
  112.     [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
  113.     lt = [LaunchTextView new];
  114.     [lt setFieldEditor:YES];
  115.     [lt setTableView:resultTable];
  116. }
  117.  
  118. - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject {
  119.     if (anObject == searchField)
  120.         return lt;
  121.     return nil;
  122. }
  123.  
  124. -(void)launch: (int)r {
  125.     [[searchField window] makeFirstResponder:searchField];
  126.     if (r < 0 || r >= [apps count])
  127.         return;
  128.     AppInfo *ai = [apps objectAtIndex:r];
  129.     if ([ai launch] == NO)
  130.         NSBeep();
  131.     else {
  132.         NSString *sv = [searchField stringValue];
  133.         sv = [sv stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  134.         if ([sv length] > 0)
  135.             [prefs setApp:[ai name] forString:sv];
  136.         //[[NSApplication sharedApplication] hide:nil];
  137.     }
  138. }
  139.  
  140. - (void)tableViewSelectionDidChange:(NSNotification *)aNotification {
  141.     if ([searchPanel firstResponder] == resultTable)
  142.         [self launch: [resultTable selectedRow]];
  143. }
  144.  
  145. - (void)windowDidBecomeKey:(NSNotification *)aNotification {
  146.     [searchField setStringValue: @@""];
  147.     [self setAllApps];
  148.     [self setApps];
  149. }
  150.  
  151. -(void)windowWillClose:(NSNotification *)aNotification {
  152.     [[NSApplication sharedApplication] terminate:nil];
  153. }
  154.  
  155. - (void)controlTextDidChange:(NSNotification *)aNotification {
  156.     [self setApps];
  157. }
  158.  
  159. -(IBAction)enterPressed: (id)sender {
  160.     [self launch: [resultTable selectedRow]];
  161. }
  162. @@end
  163. @
  164.  
  165.  
  166. 1.2
  167. log
  168. @*** empty log message ***
  169. @
  170. text
  171. @d97 1
  172. a97 1
  173.         [[NSApplication sharedApplication] hide:nil];
  174. @
  175.  
  176.  
  177. 1.1
  178. log
  179. @Initial revision
  180. @
  181. text
  182. @d74 9
  183. @
  184.  
  185.  
  186. 1.1.1.1
  187. log
  188. @RocketLauncher
  189. @
  190. text
  191. @@
  192.